package com.aurora.app.util;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {
	/**
	 * 比较当前时间和所给时间，得出几秒分钟小时。。。。。前
	 * @param now
	 * @param date
	 * @return
	 */
	public static final String getMyFormatTime(Date date){
		String time="";
		Date now = new Date();
		long diff = now.getTime() - date.getTime() ;
		//1分钟之内
		if(diff < 1000){
			time= "1秒前";
		}
		if(diff/(1000) < 60 ){
			time = (diff/(1000))+"秒前";
		}else if(diff/(1000 * 60) < 60){
			//一小时之内
			time = (diff/(1000 * 60)) + "分钟前";
		}else if(diff/(1000 * 60 * 60) < 24 ){
			//一天之内
			time = (diff/(1000 * 60 * 60 )) + "小时前";
		}else if(diff/(1000 * 60 * 60 *24) < 7){
			//七天之内
			time = (diff/(1000 * 60 * 60 * 24)) + "天前";
		}else{
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
			time = df.format(date);
		}
		return time;
	}
	
	/**
	 * 获取距离截止还有多少天，返回 剩余90天展示时间
	 * @param date
	 * @return
	 */
	public static final String getShowLastTime(Date date){
		Date now = new Date();
		long diff = now.getTime() - date.getTime() ;
		String time = "剩余"+(diff/(1000 * 60 * 60 * 24))+"天展示时间";
		return time;
	}
}
